{include file="public/headerbase" /} {include file="public/left" /}

<div class="right-content">
	<ol class="breadcrumb we7-breadcrumb">
		<div class="we7-page-title">我的账户</div>
	</ol>
	<div id="js-user-profile" ng-controller="UserProfileDisplay" ng-cloak>
		<div class="tab-content">
			<div role="tabpanel" class="tab-pane active" id="base">
				<table class="table we7-table table-hover table-form">
					<col width="140px " />
					<col />
					<col width="100px" />
					<tr>
						<th class="text-left" colspan="3">账户设置设置</th>
					</tr>
					<tr>
						<td class="table-label">用户名</td>
						<td ng-bind="user.username">{:session('username')}</td>
						<td>
							<div class="link-group">
								<a href="#name" data-toggle="modal" data-target="" ng-click="editInfo('username', user.username)">修改</a>
							</div>
						</td>
					</tr>
					<tr>
						<td class="table-label">密码</td>
						<td>******</td>
						<td>
							<div class="link-group">
								<a href="javascript:;" data-toggle="modal" data-target="#pass">修改</a>
							</div>
						</td>
					</tr>
				</table>
				<div class="modal fade" id="name" role="dialog">
					<div class="we7-modal-dialog modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
								<div class="modal-title">修改用户名</div>
							</div>
							<div class="modal-body">
								<div class="form-group">
									<input type="text" ng-model="userOriginal.username" class="form-control" placeholder="用户名" value="{:session('username')}" id="adminuser"/>
									<span class="help-block"></span>
								</div>
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-primary" onclick="queding()">确定</button>
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							</div>
						</div>
					</div>
				</div>
				<div class="modal fade" id="pass" role="dialog">
					<div class="we7-modal-dialog modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
								<div class="modal-title">修改密码</div>
							</div>
							<div class="modal-body text-center">
								<div class="we7-form" style="width: 450px; margin: 0 auto;">
									<div class="form-group">
										<label for="" class="control-label col-sm-2">原密码</label>
										<div class="form-controls col-sm-10">
											<input type="password" value="" required="required" class="form-control old-password" id="ypawd" onBlur="ymima()">

										</div>
									</div>
									<div class="form-group">
										<label for="" class="control-label col-sm-2">新密码</label>
										<div class="form-controls col-sm-10">
											<input type="password" value="" required="required" class="form-control new-password" id="xpawd">

										</div>
									</div>
									<div class="form-group">
										<label for="" class="control-label col-sm-2">确认新密码</label>
										<div class="form-controls col-sm-10">
											<input type="password" value="" required="required" class="form-control renew-password" id="cpawd" onBlur="xmima()">
										</div>
									</div>
								</div>
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-primary" onclick="savePwd()"  id="btn" >确定</button>
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	//修改用户名
	function queding(){
		var adminuser = $('#adminuser').val();
		if(adminuser=='')
		{
			util.message('用户名不能为空','','error');
		}
		$.ajax({
	        url: "{:url('Index/updatename')}",
	        data:{'adminuser':adminuser},
	        type: "post",
	        dataType: "json",
	        success: function (emg) {
	        	// alert(emg);
	           if(emg==1){
			  // alert("用户名修改成功");
	           		util.message('用户名修改成功', 'index/index', 'info');
					
	           }else if(emg==2){
	           		util.message('修改失败', '', '');
	           }
	        }
    	});
	}
	/**function ymima(){
		var ypawd = $('#ypawd').val();
		$.ajax({
	        url: "{:url('Index/selectpawd')}",
	        data:{'ypawd':ypawd},
	        type: "post",
	        dataType: "json",
	        success: function (emgs) {
	          if(emgs!=1){
	          	util.message('密码输入错误', '', '');
				
	          }
	        }
    	});
	}
	function xmima(){
		var xpawd = $('#xpawd').val();
		var cpawd = $('#cpawd').val();
		if(xpawd!=cpawd){
			util.message('两次输入密码不一致', '', '');
		}else{
			$("#btn").removeAttr("disabled");
		}
	}
	//修改密码
	function pawd(){
		var cpawd = $('#cpawd').val();
		var ypawd = $('#ypawd').val();
		var xpawd = $('#xpawd').val();
		if(ypawd!=='' && cpawd!=='' && xpawd!=='')
		{
			$.ajax({
					url: "{:url('Index/updatepawd')}",
					data:{'cpawd':cpawd},
					type: "post",
					dataType: "json",
					success: function (data) {
					  if(data==1){
							util.message('密码修改成功', "{:url('Index/index')}", '');
					   }else{
							util.message('修改失败', '', '');
					   }
					}
				});
			
		}else{
			util.message('请填写完整信息', '', '');
			return false;
		}
	}**/
	function savePwd(){
		var cpawd = $('#cpawd').val();
		var ypawd = $('#ypawd').val();
		var xpawd = $('#xpawd').val();
		if(ypawd=='' || ypawd=='' || xpawd=='')
		{
			util.message('请填写相关信息', '', '');
				return false;
		}else{
		$.ajax({
	        url: "{:url('Index/selectpawd')}",
	        data:{'ypawd':ypawd},
	        type: "post",
	        dataType: "json",
	        success: function (emgs) {
				
	          if(emgs!=1){
					util.message('原密码不正确', '', '');
	          }else{
				if(xpawd!=cpawd){
					util.message('两次输入密码不一致', '', '');
					return false;
				}else{
					
					if(ypawd!=='' && cpawd!=='' && xpawd!==''  )
						{
							if(ypawd!=cpawd)
							{
								
								$.ajax({
									url: "{:url('Index/updatepawd')}",
									data:{'cpawd':cpawd},
									type: "post",
									dataType: "json",
									success: function (data) {
									  if(data==1){
											//alert("修改成功");
											util.message('密码修改成功', "{:url('Index/index')}", 'info');
									   }else{
											util.message('修改失败', '', '');
											return false;
									   }
									}
								});
							}else{
								util.message('新密码与原密码相同', '', '');
							}
							
							
						}else{
							util.message('未填写完整信息', '', '');
							return false;
						}
				}
			  }
	        }
    	});
		}
	}
</script>

{include file="public/footer" /}